package com.wlc.socket.demo01_v3;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 发送消息的线程
 * @date 2021-07-15 14:28
 */
public class SendThread extends Thread {

    private Socket socket;

    public SendThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            OutputStream os = socket.getOutputStream();
            DataOutputStream dos = new DataOutputStream(os);
            while (true){
                Scanner sc = new Scanner(System.in);
                String str = sc.next();
                dos.writeUTF(str);
                System.out.println("发送完毕～");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
